<?php
	$html->css("/paid_listings/css/style.css",array(),null,false);
	$this->pageTitle = sprintf(__("Plans for %s"),$listing['Listing']['title']);
	$EffectivePlan = cri("PaidListings.ListingPlan")->getEffectivePlan($listing['Listing']['id']);
	$upgradePlans = cri("PaidListings.Plan")->getUpgradePlans($listing['Listing']['list_category_id']);
	foreach($upgradePlans as $key => $plan)
	{
		if($EffectivePlan->isPlanIncluded($plan['Plan']['id']))
		{
			unset($upgradePlans[$key]);
		}
	}
	$Order = cri("PaidListings.Order");
?>
<div style="padding: 5px">
<?php foreach($listingPlans as $listingPlan) {
		$order = $Order->getLatestOrder($listingPlan['ListingPlan']['id']);
?>
	<div class="plan_block">
		
		<span class="title"><?php echo $html->link($listingPlan['ListingPlan']['plan_name'],array("controller"=>'orders','action'=>"invoice",$order['Order']['id']))?></span>
		<div>
			<div class="unit size1of3">
				<span class="plan_property"><?php echo __("Current Status")?></span> <?php echo $listingPlan['ListingPlan']['status'] == ListingPlan::STATUS_INACTIVE ? __("Inactive") : __("Active")?>
				
				<?php if($listingPlan['ListingPlan']['status'] != ListingPlan::STATUS_INACTIVE && $listingPlan['ListingPlan']['plan_info']['Plan']['payment_type'] == Plan::PAYMENT_SUBSCRIPTION){?>
					<br />
					<span class="plan_property"><?php echo __("Subscription cycle period") ?></span> <?php echo $listingPlan['ListingPlan']['plan_info']['Plan']['duration_number'].' '.$listingPlan['ListingPlan']['plan_info']['Plan']['duration_period']?>
			<?php } ?>
			</div>
			<div class="unit size1of3">
				<span class="plan_property"><?php echo __("Plan price")?></span> <?php echo $order['Order']['currency_symbol'].$order['Order']['price'].'('.$order['Order']['currency'].')'?>
				<br />
				<!--<span class="plan_property"><?php echo __("Payment method")?></span><?php //echo $order['Order']['payment_handler']?>-->
			</div>
			<div class="unit size1of3">
				<?php if($listingPlan['ListingPlan']['status'] == ListingPlan::STATUS_ACTIVE || $order['Order']['status'] == Order::STATUS_COMPLETED){?>
				<span class="plan_property"><?php echo __("Activation Date") ?> </span><?php echo $time->format('Y-m-d',$order['Order']['start_date'])?>
				<span class="clear"></span>
				<div class="clear"></div>
				<span class="plan_property"><?php echo __("End Date")?></span>
				<?php echo $order['Order']['end_date'] ? $time->format('Y-m-d',$order['Order']['end_date']) : __("Never Expires") ?>
				<?php } ?>
			</div>
		</div>
	</div>
	<div class="line"></div>
<?php } ?>
</div>
<?php if(count($listingPlans) == 0){?>
	<h4><?php echo __("You haven't purchased any plan yet.")?></h4>
<?php } ?>
<?php if(count($upgradePlans)){?>
	<div style="height: 50px;">
	<a href="javascript:void(0)" onclick="tb_show(null,'#TB_inline?inlineId=upgrade_plans&height=400px&width=300px;')" class="button thickbox" style=""><?php echo __("Upgrade")?></a>
	</div>
	<div id="upgrade_plans" style="display: none">
		<?php 
			echo $form->create('ListingPlan',array("action"=>"initPlan")) ;
			echo $planDisplay->showPlans($upgradePlans);
			echo $form->input("listing_id",array("type"=>"hidden",'value'=>$listing['Listing']['id']));
			echo $form->end(__("Upgrade"));
		?>
	</div>
<?php } ?>
